package com.fzy.modules.bill.web;

import com.fzy.core.common.ApiController;
import com.fzy.core.common.ResponseData;
import com.fzy.modules.bill.entity.SoBillDetail;
import com.fzy.modules.bill.service.SoBillDetailService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 销售订单详情Controller
 */
@RestController
@RequestMapping(value = "/api/bill/so/detail")
public class SoBillDetailController extends ApiController{
    @Autowired
    SoBillDetailService soBillDetailService;
     @GetMapping()
    public ResponseEntity<ResponseData> findBySoBillId(SoBillDetail soBillDetail,
        @RequestParam(value = "page", defaultValue = "1") int page,
        @RequestParam(value = "rows", defaultValue = "10") int rows){
         return new ResponseEntity<>(success(soBillDetailService.findBySoBillId(soBillDetail,page,rows)), HttpStatus.OK);
     }

     @PostMapping()
    public ResponseEntity<ResponseData> save(SoBillDetail soBillDetail){
        if(StringUtils.isEmpty(soBillDetail.getSoBillId())){
            return new ResponseEntity<>(fail("请选择订单号！"),HttpStatus.BAD_GATEWAY);
        }
        try {
			return new ResponseEntity<>(success(soBillDetailService.saveSoBill(soBillDetail)), HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseEntity<>(fail("操作失败！"),HttpStatus.BAD_GATEWAY);
		}
    }
}
